$(function () {
    obj.init();
});
var obj = new function () {
  'use strict';
  return {
      schoolId:null,
      timeLog: null,
      dom:{
          addBtn:null
      },
      init:function () {
          this.schoolId = xhTool.getQuery('schoolId');

          this.timeLog = $('#timeWraper');
          this.dom.addBtn = $('#new');


          this.funObj().initLog();//初始化日志
          this.listener();
      },
      listener:function () {
        var $this = this;

          //新建按钮点击事件
          $this.dom.addBtn.click(function () {
             $this.funObj().openAddForm();
          });
          //删除图片
          $this.timeLog.on('click','[id^=imageDelete_]',function () {
              $this.funObj().delImg(this);
          });
          //删除
          $this.timeLog.on('click','[id^=delete_]',function () {
              $this.funObj().delLog(this);
          });
          //编辑
          $this.timeLog.on('click','[id^=edit_]',function () {
              $this.funObj().editLog(this);
          });

          $('#timeWraper').on('click','[id^=check_]',function () {
              var iSSId=$(this).attr("id").split("check_")[1];
              window.top.xhTop.showModal({
                  title:'审核跟踪信息',
                  content:'<iframe src="'+baseUrl+'school_share/check?iSSId='+iSSId+'"  style="width: 100%;;border-style: none;padding: 0px;height:130px"  scrolling="yes"   ></iframe>',
                  button:'审核通过',
                  backClose:false,
              });

          });


      },
      funObj:function () {
          var $this = this;
          return {
              openAddForm:function () {
                  window.top.xhTop.showModal({
                      title:'新建分享',
                      content:'<iframe src="'+baseUrl+'school_share/shareForm?schoolId='+$this.schoolId+'"  style="width: 100%;;border-style: none;padding: 0px;height:250px"  scrolling="yes"></iframe>',
                      button:'提交',
                      backClose:false
                  })
              },
              initLog:function () {
                  xhExtra.ajaxRequest('school_share/getShareData',{schoolId:$this.schoolId},{},function (data) {
                      timeLine.loadTimeLine($('#timeWraper'),data['data'],'交流分享',data['showDelete'],data['showEdit']);
                      $('.images').viewer();
                  });
              },
              delImg:function (target) {
                  var iSSId=$(target).attr("id").split("_")[1];
                  var rmId=$(target).attr('id').split('_')[2];
                  myWindow.initPopUp({text: '你确定要删除这张图片吗?'},function () {
                      $.ajax({
                          url:baseUrl+'school_share/ajaxDelete',
                          data:{'id':iSSId,'rmId':rmId},
                          dataType:'json',
                          type:'post',
                          success:function (data) {
                              //根据数据更新
                              timeLine.loadTimeLine($('#timeWraper'),data['data'],'交流分享',data['showDelete'],data['showEdit']);
                              $('.images').viewer();
                          },
                          error:function (result) {
                              console.log(result);
                          }
                      });
                  });
              },
              delLog:function (target) {
                  var iSSId=$(target).attr("id").split("delete_")[1];
                  myWindow.initPopUp({},function () {
                      $.ajax({
                          url : baseUrl+'school_share/delShare',
                          data : {iSSId:iSSId},
                          dataType : 'JSON',
                          type : 'POST',
                          success:function (data) {
                              location.reload();
                          },
                          error:function (result) {
                              window.top.swal('错误',result['msg'],'error');
                          }
                      });
                  });
              },
              editLog:function (target) {
                  var ssId=$(target).attr("id").split("edit_")[1];
                  window.top.xhTop.showModal({
                      title:'编辑分享',
                      content:'<iframe src="'+baseUrl+'school_share/shareForm?schoolId='+$this.schoolId+'&ssId='+ssId+'"  style="width: 100%;;border-style: none;padding: 0px;height:200px"  scrolling="yes"   ></iframe>',
                      button:'提交',
                      backClose:false,
                  });
              }

          }
      }
  }
};
